<template>
  <div class="modifyContainer">
    <div class="modify_box">
      <div v-for="(item,index) in modifyData" :key="item.id" class="item">
        <div class="head">
          <div class="data_from">
            <span>{{ index+1 }}、数据来源 : </span>
            <span>{{ item.platform_name }}</span>
          </div>
          <div class="model_from">
            <span>模型来源 : </span>
            <span v-if="item.model==1">重要新闻</span>
            <span v-if="item.model==2">情感分析</span>
            <span v-if="item.model==3">广告识别</span>
            <span v-if="item.model==4">新闻正负面</span>
          </div>
          <div class="operate">
            <el-radio-group v-model="item.tag" @change="handleRadio(item)">
              <el-radio v-if="item.model==1||item.model==3" label="1">有效</el-radio>
              <el-radio v-if="item.model==2" label="1">积极</el-radio>
              <el-radio v-if="item.model==4" label="1">正向</el-radio>
              <el-radio v-if="item.model==2||item.model==4" label="2">中性</el-radio>
              <el-radio v-if="item.model==1||item.model==3" label="0">无效</el-radio>
              <el-radio v-if="item.model==2" label="0">消极</el-radio>
              <el-radio v-if="item.model==4" label="0">负向</el-radio>
            </el-radio-group>
          </div>
        </div>
        <div class="body">{{ item.content }}</div>
      </div>
    </div>
  </div>
</template>

<script>
import { getModifyList, modifyNews } from '@/api/news'
export default {
  data() {
    return {
      modifyData: '',
      name: window.localStorage.getItem('u_name')
    }
  },
  created() {
    this.getModifyList()
  },
  methods: {
    async getModifyList() {
      const res = await getModifyList(this.name)
      this.modifyData = res.data
    },
    async handleRadio(row) {
      const newsObj = {}
      newsObj['platform_name'] = row.platform_name
      newsObj['tag'] = parseInt(row.tag)
      newsObj['username'] = window.localStorage.getItem('u_name')
      newsObj['model_name'] = row.model
      const res = await modifyNews(row.id, newsObj)
      if (res.code !== 2000) {
        return this.$message.error(res.msg)
      }
      this.$message.success('修改成功')
    }
  }
}
</script>

<style lang="scss">
.modifyContainer {
    padding:20px;
    background-color: #fff;
}

.modify_box{
    .item{
        border-bottom: 1px dotted #000;
        .head{
          display: flex;
          justify-content: space-between;
          margin: 20px 0;
          .data_from{
            span{
              &:last-child{
                color: #0D2FBD;
                font-weight: 600;
              }
            }
          }
          .model_from{
            span{
              &:last-child{
                color: #DA1919;
                font-weight: 600;
              }
            }
          }
        }
        .body{
          line-height: 30px;
          padding-bottom: 20px;
        }
    }
}
</style>
